<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AIfES 2: aimath_q7_avr_pgm.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="AIfES_logo_small.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">AIfES 2
   &#160;<span id="projectnumber">2.0.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('aimath__q7__avr__pgm_8h.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">aimath_q7_avr_pgm.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Math functions for <a class="el" href="aimath__q7_8h.html">Q7 </a> data type using AVR pgmspace.h library for constant data storage.  
<a href="#details">More...</a></p>

<p><a href="aimath__q7__avr__pgm_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a565effb18ceb9ce927a2e9bfd01174e9"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a565effb18ceb9ce927a2e9bfd01174e9">aimath_q7_avr_pgm_linear32_1</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *a, const <a class="el" href="structaitensor.html">aitensor_t</a> *b, const <a class="el" href="structaitensor.html">aitensor_t</a> *c, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a565effb18ceb9ce927a2e9bfd01174e9"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row.  <a href="aimath__q7__avr__pgm_8h.html#a565effb18ceb9ce927a2e9bfd01174e9">More...</a><br /></td></tr>
<tr class="separator:a565effb18ceb9ce927a2e9bfd01174e9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2897c9e4917a426b7a83a5fa95256add"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a2897c9e4917a426b7a83a5fa95256add">aimath_q7_avr_pgm_linear32_2</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *a, const <a class="el" href="structaitensor.html">aitensor_t</a> *b, const <a class="el" href="structaitensor.html">aitensor_t</a> *c, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a2897c9e4917a426b7a83a5fa95256add"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row.  <a href="aimath__q7__avr__pgm_8h.html#a2897c9e4917a426b7a83a5fa95256add">More...</a><br /></td></tr>
<tr class="separator:a2897c9e4917a426b7a83a5fa95256add"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7f2891f81c38a6c75ee83e30da2937b9"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a7f2891f81c38a6c75ee83e30da2937b9">aimath_q7_avr_pgm_linear32_bt_1</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *a, const <a class="el" href="structaitensor.html">aitensor_t</a> *b, const <a class="el" href="structaitensor.html">aitensor_t</a> *c, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a7f2891f81c38a6c75ee83e30da2937b9"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b (transposed) and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row.  <a href="aimath__q7__avr__pgm_8h.html#a7f2891f81c38a6c75ee83e30da2937b9">More...</a><br /></td></tr>
<tr class="separator:a7f2891f81c38a6c75ee83e30da2937b9"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a555535953ea7986db3dcf491944b03f2"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a555535953ea7986db3dcf491944b03f2">aimath_q7_avr_pgm_linear32_bt_2</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *a, const <a class="el" href="structaitensor.html">aitensor_t</a> *b, const <a class="el" href="structaitensor.html">aitensor_t</a> *c, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a555535953ea7986db3dcf491944b03f2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row.  <a href="aimath__q7__avr__pgm_8h.html#a555535953ea7986db3dcf491944b03f2">More...</a><br /></td></tr>
<tr class="separator:a555535953ea7986db3dcf491944b03f2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a53d817c9981488e8d0dacb91320cda9f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a53d817c9981488e8d0dacb91320cda9f">aimath_q7_avr_pgm_relu</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *x, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a53d817c9981488e8d0dacb91320cda9f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the rectifier (ReLU) value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor.  <a href="aimath__q7__avr__pgm_8h.html#a53d817c9981488e8d0dacb91320cda9f">More...</a><br /></td></tr>
<tr class="separator:a53d817c9981488e8d0dacb91320cda9f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad4d2f63c565e7d4b9ac2cf7aef6c4844"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#ad4d2f63c565e7d4b9ac2cf7aef6c4844">aimath_q7_avr_pgm_leaky_relu</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *x, const void *alpha, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:ad4d2f63c565e7d4b9ac2cf7aef6c4844"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the leaky rectifier (leaky ReLU) value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor.  <a href="aimath__q7__avr__pgm_8h.html#ad4d2f63c565e7d4b9ac2cf7aef6c4844">More...</a><br /></td></tr>
<tr class="separator:ad4d2f63c565e7d4b9ac2cf7aef6c4844"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a491ba7e29be29a27051c9a483afb983c"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a491ba7e29be29a27051c9a483afb983c">aimath_q7_avr_pgm_elu</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *x, const void *alpha, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a491ba7e29be29a27051c9a483afb983c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the exponential rectifier (ELU) value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor.  <a href="aimath__q7__avr__pgm_8h.html#a491ba7e29be29a27051c9a483afb983c">More...</a><br /></td></tr>
<tr class="separator:a491ba7e29be29a27051c9a483afb983c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ad79eb5d753d38e97347096fd64783a46"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#ad79eb5d753d38e97347096fd64783a46">aimath_q7_avr_pgm_sigmoid</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *x, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:ad79eb5d753d38e97347096fd64783a46"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the sigmoid of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor.  <a href="aimath__q7__avr__pgm_8h.html#ad79eb5d753d38e97347096fd64783a46">More...</a><br /></td></tr>
<tr class="separator:ad79eb5d753d38e97347096fd64783a46"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a0d03214721c6da17a577865834634de7"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a0d03214721c6da17a577865834634de7">aimath_q7_avr_pgm_tanh</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *x, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a0d03214721c6da17a577865834634de7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the tanh of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor.  <a href="aimath__q7__avr__pgm_8h.html#a0d03214721c6da17a577865834634de7">More...</a><br /></td></tr>
<tr class="separator:a0d03214721c6da17a577865834634de7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7a63ddf00a06d19456f79a1cf49b0ef2"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#a7a63ddf00a06d19456f79a1cf49b0ef2">aimath_q7_avr_pgm_softsign</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *x, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:a7a63ddf00a06d19456f79a1cf49b0ef2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the softsign value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor.  <a href="aimath__q7__avr__pgm_8h.html#a7a63ddf00a06d19456f79a1cf49b0ef2">More...</a><br /></td></tr>
<tr class="separator:a7a63ddf00a06d19456f79a1cf49b0ef2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aab25d76339b480c860dbc909cfd4049c"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aimath__q7__avr__pgm_8h.html#aab25d76339b480c860dbc909cfd4049c">aimath_q7_avr_pgm_softmax</a> (const <a class="el" href="structaitensor.html">aitensor_t</a> *x, <a class="el" href="structaitensor.html">aitensor_t</a> *result)</td></tr>
<tr class="memdesc:aab25d76339b480c860dbc909cfd4049c"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculates the softmax value of each batch element (row) of a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor.  <a href="aimath__q7__avr__pgm_8h.html#aab25d76339b480c860dbc909cfd4049c">More...</a><br /></td></tr>
<tr class="separator:aab25d76339b480c860dbc909cfd4049c"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Math functions for <a class="el" href="aimath__q7_8h.html">Q7 </a> data type using AVR pgmspace.h library for constant data storage. </p>
<dl class="section version"><dt>Version</dt><dd>2.2.0 </dd></dl>
<dl class="section copyright"><dt>Copyright</dt><dd>Copyright (C) 2020-2023 Fraunhofer Institute for Microelectronic Circuits and Systems. All rights reserved.<br  />
<br  />
 AIfES is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br  />
<br  />
 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.<br  />
<br  />
 You should have received a copy of the GNU Affero General Public License along with this program. If not, see <a href="https://www.gnu.org/licenses/">https://www.gnu.org/licenses/</a>.</dd></dl>
<p>These functions modify the default implementation of the Q7 math functions to work with parameters, stored in the program memory of AVR controllers.</p>
<p>The library <a href="https://www.nongnu.org/avr-libc/user-manual/pgmspace_8h.html">avr/pgmspace.h</a> is required. </p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="a491ba7e29be29a27051c9a483afb983c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a491ba7e29be29a27051c9a483afb983c">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_elu()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_elu </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>alpha</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the exponential rectifier (ELU) value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor. </p>
<p>The quantization parameters x must be defined constant in PROGMEM.</p>
<p>This function wraps the function <a class="el" href="aimath__f32__default_8h.html#a76692ffb6acf0f7a291d6b4c86311edf" title="Calculates the exponential rectifier (ELU) value of each element in a F32  tensor.">aimath_f32_default_elu()</a> internally.</p>
<p class="formulaDsp">
\[ result_{i} = \begin{cases} \alpha \cdot (e^{x_i} - 1) &amp; \text{if } x_i &lt; 0 \\ x_i &amp; \text{if } x_i \geq 0 \end{cases} \]
</p>
<p>The ELU is calculated with a piecewise linear approximation to avoid using exponential functions.</p>
<p class="formulaDsp">
\[ result_{i} = \begin{cases} x_i &amp; \text{if } 0 \leq x_i\\ \alpha \cdot 0.625 \cdot x_i &amp; \text{if } -1 \leq x &lt; 0\\ \alpha \cdot (0.25 \cdot x_i - 0.375) &amp; \text{if } -2 \leq x &lt; -1\\ \alpha \cdot (0.09375 \cdot x_i - 0.6875) &amp; \text{if } -3 \leq x &lt; -2\\ \alpha \cdot (0.03125 \cdot x_i - 0.875) &amp; \text{if } -4 \leq x &lt; -3\\ - \alpha &amp; \text{if } x &lt; -4 \end{cases} \]
</p>
<p><b>The quantization parameters of the result tensor are set to {shift = x.shift, zero_point = x.zero_point} by the function because the output values are in the interval (max(-alpha, min(x)), max(x)].</b></p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t x_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> x_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t x_data[2*3] = {  2,  -4,   6,</div>
<div class="line">                       -8,  10, -12};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> x = AITENSOR_2D_Q7(x_shape, &amp;x_params, x_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="structaiscalar__q7.html">aiscalar_q7_t</a> alpha = AISCALAR_Q7(1.0f, 0, 0);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {2, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t result_data[2*3];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a491ba7e29be29a27051c9a483afb983c">aimath_q7_avr_pgm_elu</a>(&amp;x, &amp;alpha, &amp;result);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a>(&amp;result);</div>
<div class="ttc" id="aaimath__basic_8h_html_ab10c8d06990943806f0be8fcc6af03fc"><div class="ttname"><a href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a></div><div class="ttdeci">void print_aitensor(const aitensor_t *tensor)</div><div class="ttdoc">Printing a tensor to console.</div></div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a491ba7e29be29a27051c9a483afb983c"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a491ba7e29be29a27051c9a483afb983c">aimath_q7_avr_pgm_elu</a></div><div class="ttdeci">void aimath_q7_avr_pgm_elu(const aitensor_t *x, const void *alpha, aitensor_t *result)</div><div class="ttdoc">Calculates the exponential rectifier (ELU) value of each element in a Q7  tensor.</div></div>
<div class="ttc" id="astructaimath__q7__params_html"><div class="ttname"><a href="structaimath__q7__params.html">aimath_q7_params</a></div><div class="ttdoc">Parameters used for the quantized Q7  values, used as property of a tensor.</div><div class="ttdef"><b>Definition:</b> aimath_q7.h:148</div></div>
<div class="ttc" id="astructaiscalar__q7_html"><div class="ttname"><a href="structaiscalar__q7.html">aiscalar_q7</a></div><div class="ttdoc">Single quantized Q7  value/scalar.</div><div class="ttdef"><b>Definition:</b> aimath_q7.h:155</div></div>
<div class="ttc" id="astructaitensor_html"><div class="ttname"><a href="structaitensor.html">aitensor</a></div><div class="ttdoc">A tensor in AIfES.</div><div class="ttdef"><b>Definition:</b> aifes_math.h:89</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*x</td><td>Q7 tensor to calculate the ELU from (N-D tensor) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*alpha</td><td>Scalar \( \alpha \) (type aiscalar_q7_t) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 tensor (N-D tensor) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ad4d2f63c565e7d4b9ac2cf7aef6c4844"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad4d2f63c565e7d4b9ac2cf7aef6c4844">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_leaky_relu()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_leaky_relu </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const void *&#160;</td>
          <td class="paramname"><em>alpha</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the leaky rectifier (leaky ReLU) value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor. </p>
<p>The quantization parameters x must be defined constant in PROGMEM.</p>
<p>This function wraps the function <a class="el" href="aimath__f32__default_8h.html#afaafd34ad1adc476a7c120dce8f39498" title="Calculates the leaky rectifier (leaky ReLU) value of each element in a F32  tensor.">aimath_f32_default_leaky_relu()</a> internally.</p>
<p class="formulaDsp">
\[ result_{i} = \begin{cases} \alpha \cdot x_i &amp; \text{if } x_i &lt; 0 \\ x_i &amp; \text{if } x_i \geq 0 \end{cases} \]
</p>
<p><b>The quantization parameters of the result tensor are set to {shift = x.shift, zero_point = x.zero_point} by the function because the output values are in the interval (alpha * min(x), max(x)].</b></p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t x_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> x_params PROGMEM = {6, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t x_data[2*3] = {  2,  -4,   6,</div>
<div class="line">                       -8,  10, -12};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> x = AITENSOR_2D_Q7(x_shape, &amp;x_params, x_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="structaiscalar__q7.html">aiscalar_q7_t</a> alpha = AISCALAR_Q7(0.01f, 10, 0);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {2, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t result_data[2*3];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#ad4d2f63c565e7d4b9ac2cf7aef6c4844">aimath_q7_avr_pgm_leaky_relu</a>(&amp;x, &amp;alpha, &amp;result);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a>(&amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_ad4d2f63c565e7d4b9ac2cf7aef6c4844"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#ad4d2f63c565e7d4b9ac2cf7aef6c4844">aimath_q7_avr_pgm_leaky_relu</a></div><div class="ttdeci">void aimath_q7_avr_pgm_leaky_relu(const aitensor_t *x, const void *alpha, aitensor_t *result)</div><div class="ttdoc">Calculates the leaky rectifier (leaky ReLU) value of each element in a Q7  tensor.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*x</td><td>Q7 tensor to calculate the leaky ReLU from (N-D tensor) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*alpha</td><td>Scalar \( \alpha \) (type aiscalar_q7_t) for the leakage </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 tensor (N-D tensor) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a565effb18ceb9ce927a2e9bfd01174e9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a565effb18ceb9ce927a2e9bfd01174e9">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_linear32_1()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_linear32_1 </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>a</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>b</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>c</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row. </p>
<p>The data of b and c and the quantization parameters of a, b, c and result must be defined constant in PROGMEM.</p>
<p>Same functionality as aimath_f32_default_linear32().</p>
<p>The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to a * b.</p>
<p>** The quantization parameters of the vector c have to be {zero_point = 0, shift = a.shift + b.shift}! **</p>
<p class="formulaDsp">
\[ result = a \cdot b + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \]
</p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t a_shape[2] = {3, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> a_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t a_data[3*3] = { 2,  4,  6,</div>
<div class="line">                       8, 10, 12,</div>
<div class="line">                      14, 16, 18};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> a = AITENSOR_2D_Q7(a_shape, &amp;a_params, a_data);</div>
<div class="line"> </div>
<div class="line">uint16_t b_shape[2] = {3, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> b_params PROGMEM = {2, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int8_t b_data[3*2] PROGMEM = {4, 0,</div>
<div class="line">                                    0, 4,</div>
<div class="line">                                    0, 0};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> b = AITENSOR_2D_Q7(b_shape, &amp;b_params, b_data);</div>
<div class="line"> </div>
<div class="line">uint16_t c_shape[2] = {1, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q31__params.html">aimath_q31_params_t</a> c_params PROGMEM = {3, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int32_t c_data[1*2] PROGMEM = {16, 40};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> c = AITENSOR_2D_Q31(c_shape, &amp;c_params, c_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {3, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t result_data[3*2];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a565effb18ceb9ce927a2e9bfd01174e9">aimath_q7_avr_pgm_linear32_1</a>(&amp;a, &amp;b, &amp;c, &amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a565effb18ceb9ce927a2e9bfd01174e9"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a565effb18ceb9ce927a2e9bfd01174e9">aimath_q7_avr_pgm_linear32_1</a></div><div class="ttdeci">void aimath_q7_avr_pgm_linear32_1(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)</div><div class="ttdoc">Performs a matrix multiplication of Q7  matrices a and b and adds a Q31  vector c to each row.</div></div>
<div class="ttc" id="astructaimath__q31__params_html"><div class="ttname"><a href="structaimath__q31__params.html">aimath_q31_params</a></div><div class="ttdoc">Parameters used for the quantized Q31  values, used as property of a tensor.</div><div class="ttdef"><b>Definition:</b> aimath_q31.h:149</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*a</td><td>Q7 matrix a (2D tensor of shape [N x K]) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*b</td><td>Q7 matrix b (2D tensor of shape [K x M]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*c</td><td>Q31 vector c (2D tensor of shape [1 x M]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 matrix (2D tensor of shape [N x M]) (quantization parameters const in PROGMEM) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a2897c9e4917a426b7a83a5fa95256add"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a2897c9e4917a426b7a83a5fa95256add">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_linear32_2()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_linear32_2 </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>a</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>b</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>c</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row. </p>
<p>The data of b and c and the quantization parameters of b, c and result (not of a!) must be defined constant in PROGMEM.</p>
<p>Same functionality as aimath_f32_default_linear32().</p>
<p>The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to a * b.</p>
<p>** The quantization parameters of the vector c have to be {zero_point = 0, shift = a.shift + b.shift}! **</p>
<p class="formulaDsp">
\[ result = a \cdot b + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \]
</p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t a_shape[2] = {3, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> a_params = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t a_data[3*3] = { 2,  4,  6,</div>
<div class="line">                       8, 10, 12,</div>
<div class="line">                      14, 16, 18};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> a = AITENSOR_2D_Q7(a_shape, &amp;a_params, a_data);</div>
<div class="line"> </div>
<div class="line">uint16_t b_shape[2] = {3, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> b_params PROGMEM = {2, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int8_t b_data[3*2] PROGMEM = {4, 0,</div>
<div class="line">                                    0, 4,</div>
<div class="line">                                    0, 0};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> b = AITENSOR_2D_Q7(b_shape, &amp;b_params, b_data);</div>
<div class="line"> </div>
<div class="line">uint16_t c_shape[2] = {1, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q31__params.html">aimath_q31_params_t</a> c_params PROGMEM = {3, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int32_t c_data[1*2] PROGMEM = {16, 40};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> c = AITENSOR_2D_Q31(c_shape, &amp;c_params, c_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {3, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t result_data[3*2];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a2897c9e4917a426b7a83a5fa95256add">aimath_q7_avr_pgm_linear32_2</a>(&amp;a, &amp;b, &amp;c, &amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a2897c9e4917a426b7a83a5fa95256add"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a2897c9e4917a426b7a83a5fa95256add">aimath_q7_avr_pgm_linear32_2</a></div><div class="ttdeci">void aimath_q7_avr_pgm_linear32_2(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)</div><div class="ttdoc">Performs a matrix multiplication of Q7  matrices a and b and adds a Q31  vector c to each row.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*a</td><td>Q7 matrix a (2D tensor of shape [N x K]) </td></tr>
    <tr><td class="paramname">*b</td><td>Q7 matrix b (2D tensor of shape [K x M]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*c</td><td>Q31 vector c (2D tensor of shape [1 x M]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 matrix (2D tensor of shape [N x M]) (quantization parameters const in PROGMEM) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a7f2891f81c38a6c75ee83e30da2937b9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7f2891f81c38a6c75ee83e30da2937b9">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_linear32_bt_1()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_linear32_bt_1 </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>a</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>b</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>c</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b (transposed) and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row. </p>
<p>The data of b and c and the quantization parameters of a, b, c and result must be defined constant in PROGMEM.</p>
<p>The b matrix has to be transposed.</p>
<p>Same functionality as aimath_f32_default_linear32_bt().</p>
<p>The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to \( a * b^T \).</p>
<p><b>The quantization parameters of the vector c have to be {zero_point = 0, shift = a.shift + b.shift}!</b></p>
<p class="formulaDsp">
\[ result = a \cdot b^T + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \]
</p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t a_shape[2] = {3, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> a_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t a_data[3*3] = { 2,  4,  6,</div>
<div class="line">                       8, 10, 12,</div>
<div class="line">                      14, 16, 18};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> a = AITENSOR_2D_Q7(a_shape, &amp;a_params, a_data);</div>
<div class="line"> </div>
<div class="line">uint16_t b_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> b_params PROGMEM = {2, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int8_t b_data[2*3] PROGMEM = {4, 0, 0,</div>
<div class="line">                                    0, 4, 0};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> b = AITENSOR_2D_Q7(b_shape, &amp;b_params, b_data);</div>
<div class="line"> </div>
<div class="line">uint16_t c_shape[2] = {1, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q31__params.html">aimath_q31_params_t</a> c_params PROGMEM = {3, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int32_t c_data[1*2] PROGMEM = {16, 40};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> c = AITENSOR_2D_Q31(c_shape, &amp;c_params, c_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {3, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t result_data[3*2];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a7f2891f81c38a6c75ee83e30da2937b9">aimath_q7_avr_pgm_linear32_bt_1</a>(&amp;a, &amp;b, &amp;c, &amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a7f2891f81c38a6c75ee83e30da2937b9"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a7f2891f81c38a6c75ee83e30da2937b9">aimath_q7_avr_pgm_linear32_bt_1</a></div><div class="ttdeci">void aimath_q7_avr_pgm_linear32_bt_1(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)</div><div class="ttdoc">Performs a matrix multiplication of Q7  matrices a and b (transposed) and adds a Q31  vector c to eac...</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*a</td><td>Q7 matrix a (2D tensor of shape [N x K]) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*b</td><td>Q7 matrix b (2D tensor of shape [M x K]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*c</td><td>Q31 vector c (2D tensor of shape [1 x M]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 matrix (2D tensor of shape [N x M]) (quantization parameters const in PROGMEM) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a555535953ea7986db3dcf491944b03f2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a555535953ea7986db3dcf491944b03f2">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_linear32_bt_2()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_linear32_bt_2 </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>a</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>b</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>c</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Performs a matrix multiplication of <a class="el" href="aimath__q7_8h.html">Q7 </a> matrices a and b and adds a <a class="el" href="aimath__q31_8h.html">Q31 </a> vector c to each row. </p>
<p>The data of b and c and the quantization parameters of b, c and result (not of a!) must be defined constant in PROGMEM.</p>
<p>The b matrix has to be transposed.</p>
<p>Same functionality as aimath_f32_default_linear32().</p>
<p>The addition of the horizontal vector c is performed via broadcast, i.e. element wise in each column Mathematically this broadcast is equal to multiplying c with an vertical vector (with the same number of elements as c) and adding the result to \( a * b^T \).</p>
<p>** The quantization parameters of the vector c have to be {zero_point = 0, shift = a.shift + b.shift}! **</p>
<p class="formulaDsp">
\[ result = a \cdot b^T + \left( \begin{array}{c} 1 \\ 1 \\ \vdots \\ 1 \\ \end{array}\right) \cdot c \]
</p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t a_shape[2] = {3, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> a_params = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t a_data[3*3] = { 2,  4,  6,</div>
<div class="line">                       8, 10, 12,</div>
<div class="line">                      14, 16, 18};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> a = AITENSOR_2D_Q7(a_shape, &amp;a_params, a_data);</div>
<div class="line"> </div>
<div class="line">uint16_t b_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> b_params PROGMEM = {2, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int8_t b_data[2*3] PROGMEM = {4, 0, 0,</div>
<div class="line">                                    0, 4, 0};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> b = AITENSOR_2D_Q7(b_shape, &amp;b_params, b_data);</div>
<div class="line"> </div>
<div class="line">uint16_t c_shape[2] = {1, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q31__params.html">aimath_q31_params_t</a> c_params PROGMEM = {3, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line"><span class="keyword">const</span> int32_t c_data[1*2] PROGMEM = {16, 40};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> c = AITENSOR_2D_Q31(c_shape, &amp;c_params, c_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {3, 2};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t result_data[3*2];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a555535953ea7986db3dcf491944b03f2">aimath_q7_avr_pgm_linear32_bt_2</a>(&amp;a, &amp;b, &amp;c, &amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a555535953ea7986db3dcf491944b03f2"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a555535953ea7986db3dcf491944b03f2">aimath_q7_avr_pgm_linear32_bt_2</a></div><div class="ttdeci">void aimath_q7_avr_pgm_linear32_bt_2(const aitensor_t *a, const aitensor_t *b, const aitensor_t *c, aitensor_t *result)</div><div class="ttdoc">Performs a matrix multiplication of Q7  matrices a and b and adds a Q31  vector c to each row.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*a</td><td>Q7 matrix a (2D tensor of shape [N x K]) </td></tr>
    <tr><td class="paramname">*b</td><td>Q7 matrix b (2D tensor of shape [M x K]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*c</td><td>Q31 vector c (2D tensor of shape [1 x M]) (data and quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 matrix (2D tensor of shape [N x M]) (quantization parameters const in PROGMEM) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a53d817c9981488e8d0dacb91320cda9f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a53d817c9981488e8d0dacb91320cda9f">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_relu()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_relu </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the rectifier (ReLU) value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor. </p>
<p>The quantization parameters x must be defined constant in PROGMEM.</p>
<p>This function wraps the function <a class="el" href="aimath__f32__default_8h.html#a69ea48225650ecaf3493d137f3e91c4e" title="Calculates the rectifier (ReLU) value of each element in a F32  tensor.">aimath_f32_default_relu()</a> internally.</p>
<p class="formulaDsp">
\[ result_{i} = max(0, x_{i}) \]
</p>
<p><b>The quantization parameters of the result tensor are set to {shift = x.shift, zero_point = x.zero_point} by the function because the output values are in the interval [0, max(x)].</b></p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t x_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> x_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t x_data[2*3] = {  2,  -4,   6,</div>
<div class="line">                       -8,  10, -12};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> x = AITENSOR_2D_Q7(x_shape, &amp;x_params, x_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {2, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params;</div>
<div class="line">int8_t result_data[2*3];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a53d817c9981488e8d0dacb91320cda9f">aimath_q7_avr_pgm_relu</a>(&amp;x, &amp;result);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a>(&amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a53d817c9981488e8d0dacb91320cda9f"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a53d817c9981488e8d0dacb91320cda9f">aimath_q7_avr_pgm_relu</a></div><div class="ttdeci">void aimath_q7_avr_pgm_relu(const aitensor_t *x, aitensor_t *result)</div><div class="ttdoc">Calculates the rectifier (ReLU) value of each element in a Q7  tensor.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*x</td><td>Q7 tensor to calculate the ReLU from (N-D tensor) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 tensor (N-D tensor) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ad79eb5d753d38e97347096fd64783a46"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad79eb5d753d38e97347096fd64783a46">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_sigmoid()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_sigmoid </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the sigmoid of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor. </p>
<p>The quantization parameters x must be defined constant in PROGMEM.</p>
<p>This function wraps the function <a class="el" href="aimath__f32__default_8h.html#a9c2af96bf91c4443ab75036f585fdba3" title="Calculates the sigmoid of each element in a F32  tensor.">aimath_f32_default_sigmoid()</a> internally.</p>
<p class="formulaDsp">
\[ result_{i} = \sigma(x_{i}) = \frac{1}{1 + e^{-x_{i}}} \]
</p>
<p>The sigmoid is calculated with a piecewise linear approximation (PLAN) to avoid using exponential functions.</p>
<p class="formulaDsp">
\[ result_{i} = \sigma_{PLAN}(x_i) = \begin{cases} 1 &amp; \text{if } 5 \leq x_i\\ 0.03125 \cdot |x_i| + 0.84375 &amp; \text{if } 2.375 \leq x_i &lt; 5\\ 0.0125 \cdot |x_i| + 0.625 &amp; \text{if } 1 \leq x_i &lt; 2.375\\ 0.25 \cdot |x_i| + 0.5 &amp; \text{if } 0 \leq x_i &lt; 1\\ 1 - \sigma_{PLAN}(- x_i) &amp; \text{if } x_i &lt; 0\\ \end{cases} \]
</p>
<p><b>The quantization parameters of the result tensor are set to {shift = 8, zero_point = -2^7} by the function because the output values are in the interval (0, 1).</b></p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t x_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> x_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t x_data[2*3] = {  2,  -4,   6,</div>
<div class="line">                       -8,  10, -12};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> x = AITENSOR_2D_Q7(x_shape, &amp;x_params, x_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {2, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params;</div>
<div class="line">int8_t result_data[2*3];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#ad79eb5d753d38e97347096fd64783a46">aimath_q7_avr_pgm_sigmoid</a>(&amp;x, &amp;result);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a>(&amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_ad79eb5d753d38e97347096fd64783a46"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#ad79eb5d753d38e97347096fd64783a46">aimath_q7_avr_pgm_sigmoid</a></div><div class="ttdeci">void aimath_q7_avr_pgm_sigmoid(const aitensor_t *x, aitensor_t *result)</div><div class="ttdoc">Calculates the sigmoid of each element in a Q7  tensor.</div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd>Sigmoid PLAN: <a href="https://www.researchgate.net/figure/Comparative-representation-of-the-sigmoid-function-and-PLAN-approximation_fig7_228618304">https://www.researchgate.net/figure/Comparative-representation-of-the-sigmoid-function-and-PLAN-approximation_fig7_228618304</a></dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*x</td><td>Q7 tensor to calculate the sigmoid from (N-D tensor) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 tensor (N-D tensor) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="aab25d76339b480c860dbc909cfd4049c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aab25d76339b480c860dbc909cfd4049c">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_softmax()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_softmax </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the softmax value of each batch element (row) of a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor. </p>
<p>The quantization parameters x must be defined constant in PROGMEM.</p>
<p>This function wraps the function <a class="el" href="aimath__f32__default_8h.html#ac14896a86a6600a4be48b84c9977acaf" title="Calculates the softmax value of each row of a F32  matrix.">aimath_f32_default_softmax()</a> internally.</p>
<p class="formulaDsp">
\[ result_{i} = \frac{e^{x_i}}{\sum_{j=1}^{K} e^{x_j}} \]
</p>
<p><b>The quantization parameters of the result tensor are set to {shift = 8, zero_point = -128} by the function because the output values are in the interval (0, 1).</b></p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t x_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> x_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t x_data[2*3] = {  2,  -4,   6,</div>
<div class="line">                       -8,  10, -12};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> x = AITENSOR_2D_Q7(x_shape, &amp;x_params, x_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {2, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params;</div>
<div class="line">int8_t result_data[2*3];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#aab25d76339b480c860dbc909cfd4049c">aimath_q7_avr_pgm_softmax</a>(&amp;x, &amp;result);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a>(&amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_aab25d76339b480c860dbc909cfd4049c"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#aab25d76339b480c860dbc909cfd4049c">aimath_q7_avr_pgm_softmax</a></div><div class="ttdeci">void aimath_q7_avr_pgm_softmax(const aitensor_t *x, aitensor_t *result)</div><div class="ttdoc">Calculates the softmax value of each batch element (row) of a Q7  tensor.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*x</td><td>Q7 tensor to calculate the softmax from (N-D tensor) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 tensor (N-D tensor) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a7a63ddf00a06d19456f79a1cf49b0ef2"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7a63ddf00a06d19456f79a1cf49b0ef2">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_softsign()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_softsign </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the softsign value of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor. </p>
<p>The quantization parameters x must be defined constant in PROGMEM.</p>
<p>This function wraps the function <a class="el" href="aimath__f32__default_8h.html#a6f36c52ff560b8172098f69aab5389c9" title="Calculates the softsign value of each element in a F32  tensor.">aimath_f32_default_softsign()</a> internally.</p>
<p class="formulaDsp">
\[ result_{i} = \frac {x_i} {1 + |x_i|} \]
</p>
<p><b>The quantization parameters of the result tensor are set to {shift = 7, zero_point = 0} by the function because the output values are in the interval (-1, 1).</b></p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t x_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> x_params PROGMEM = {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t x_data[2*3] = {  2,  -4,   6,</div>
<div class="line">                       -8,  10, -12};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> x = AITENSOR_2D_Q7(x_shape, &amp;x_params, x_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {2, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params;</div>
<div class="line">int8_t result_data[2*3];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a7a63ddf00a06d19456f79a1cf49b0ef2">aimath_q7_avr_pgm_softsign</a>(&amp;x, &amp;result);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a>(&amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a7a63ddf00a06d19456f79a1cf49b0ef2"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a7a63ddf00a06d19456f79a1cf49b0ef2">aimath_q7_avr_pgm_softsign</a></div><div class="ttdeci">void aimath_q7_avr_pgm_softsign(const aitensor_t *x, aitensor_t *result)</div><div class="ttdoc">Calculates the softsign value of each element in a Q7  tensor.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*x</td><td>Q7 tensor to calculate the softsign from (N-D tensor) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 tensor (N-D tensor) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a0d03214721c6da17a577865834634de7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a0d03214721c6da17a577865834634de7">&#9670;&nbsp;</a></span>aimath_q7_avr_pgm_tanh()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aimath_q7_avr_pgm_tanh </td>
          <td>(</td>
          <td class="paramtype">const <a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculates the tanh of each element in a <a class="el" href="aimath__q7_8h.html">Q7 </a> tensor. </p>
<p>The quantization parameters x must be defined constant in PROGMEM.</p>
<p>This function wraps the function <a class="el" href="aimath__f32__default_8h.html#abd86f478417339f44905ede947a5e089" title="Calculates the tanh of each element in a F32  tensor.">aimath_f32_default_tanh()</a> internally.</p>
<p class="formulaDsp">
\[ result_{i} = \tanh(x_{i}) = \frac{e^{x_i} - e^{-x_i}}{e^{x_i} + e^{-x_i}} \]
</p>
<p>The tanh is calculated with a piecewise linear approximation (PLA) to avoid using exponential functions.</p>
<p class="formulaDsp">
\[ result_{i} = \tanh_{PLA}(x_i) = 2 \cdot \sigma(2x_i) - 1 = \begin{cases} 1 &amp; \text{if } 5 \leq x_i\\ 0.0625 \cdot |x_i| + 0.6875 &amp; \text{if } 2.375 \leq x_i &lt; 5\\ 0.25 \cdot |x_i| + 0.25 &amp; \text{if } 1 \leq x_i &lt; 2.375\\ 0.5 \cdot |x_i| &amp; \text{if } 0 \leq x_i &lt; 1\\ - \tanh_{PLA}(- x_i) &amp; \text{if } x_i &lt; 0\\ \end{cases} \]
</p>
<p><b>The quantization parameters of the result tensor are set to {shift = 7, zero_point = 0} by the function because the output values are in the interval (-1, 1).</b></p>
<p>Example: </p><div class="fragment"><div class="line">uint16_t x_shape[2] = {2, 3};</div>
<div class="line"><span class="keyword">const</span> <a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> x_params PROGMEM= {1, 0}; <span class="comment">// {shift, zero point}</span></div>
<div class="line">int8_t x_data[2*3] = {  2,  -4,   6,</div>
<div class="line">                       -8,  10, -12};</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> x = AITENSOR_2D_Q7(x_shape, &amp;x_params, x_data);</div>
<div class="line"> </div>
<div class="line">uint16_t result_shape[2] = {2, 3};</div>
<div class="line"><a class="code" href="structaimath__q7__params.html">aimath_q7_params_t</a> result_params;</div>
<div class="line">int8_t result_data[2*3];</div>
<div class="line"><a class="code" href="structaitensor.html">aitensor_t</a> result = AITENSOR_2D_Q7(result_shape, &amp;result_params, result_data);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__q7__avr__pgm_8h.html#a0d03214721c6da17a577865834634de7">aimath_q7_avr_pgm_tanh</a>(&amp;x, &amp;result);</div>
<div class="line"> </div>
<div class="line"><a class="code" href="aimath__basic_8h.html#ab10c8d06990943806f0be8fcc6af03fc">print_aitensor</a>(&amp;result);</div>
<div class="ttc" id="aaimath__q7__avr__pgm_8h_html_a0d03214721c6da17a577865834634de7"><div class="ttname"><a href="aimath__q7__avr__pgm_8h.html#a0d03214721c6da17a577865834634de7">aimath_q7_avr_pgm_tanh</a></div><div class="ttdeci">void aimath_q7_avr_pgm_tanh(const aitensor_t *x, aitensor_t *result)</div><div class="ttdoc">Calculates the tanh of each element in a Q7  tensor.</div></div>
</div><!-- fragment --><dl class="section see"><dt>See also</dt><dd>Sigmoid PLAN: <a href="https://www.researchgate.net/figure/Comparative-representation-of-the-sigmoid-function-and-PLAN-approximation_fig7_228618304">https://www.researchgate.net/figure/Comparative-representation-of-the-sigmoid-function-and-PLAN-approximation_fig7_228618304</a></dd></dl>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*x</td><td>Q7 tensor to calculate the tanh from (N-D tensor) (quantization parameters const in PROGMEM) </td></tr>
    <tr><td class="paramname">*result</td><td>Resulting Q7 tensor (N-D tensor) </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_1e5d3661ed79af157d57e64a38265d09.html">basic</a></li><li class="navelem"><a class="el" href="dir_fb1774f2d451d1d60e2f94b58c26876a.html">avr_pgm</a></li><li class="navelem"><a class="el" href="dir_716836aaa50c3d724b5b6035350ace4c.html">aimath</a></li><li class="navelem"><a class="el" href="aimath__q7__avr__pgm_8h.html">aimath_q7_avr_pgm.h</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
